new Vue({
	el: '#app',
	data: function () {
		return {
			loading:false,//进去的加载中显示
			host: window.location.protocol+'//'+window.location.host,
			communityId:'',
			msg:'请求超时',
			errorPopup:false,
			showErrorMsg:false,
			itemJson:{},
			auditId:'',
			auditFile1Path:'',
			auditFile2Path:'',
			auditFile3Path:'',
			submitBstap:true,
			refuseReasonValue:'',
			userId:'',	
			ImagePreviewList:[],
			requestHeaders:'',
		}
	},
	created() {
		var localStorageCommunityId=JSON.parse(localStorage.getItem('hc_currentCommunityInfo'))
		if(localStorageCommunityId){
			this.communityId=localStorageCommunityId.communityId?localStorageCommunityId.communityId:this.getUrlParam("communityId");
		}else{
			this.communityId=this.getUrlParam("communityId");
		}	
		this.requestHeaders=getRequestHeaders('00',this.communityId);//获取请求头
        // console.log(this.requestHeaders)
		this.auditId=this.getUrlParam("auditId");
		this.loadListData();
	},
	mounted(){
		var that=this;
	},
	filters: {
		subStringThree: function (value) {
			if (!value) return ''
			return value.substring(0,3)
		}
	},
	methods: {
		getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if (r != null) return unescape(r[2]);
			return null; //返回参数值
		},
		loadListData(){
			let that=this;
			let url=this.host+'/app/userAudit.listUserAudits';
			let filePath=this.host + "/callComponent/download/getFile/file"; 
			let params={
				page: 1,
				row: 1,
				auditId:this.auditId,
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询审核详情',res);
					if(res.code=='0'){
						var data=res.data[0];
						that.userId=data.userId;
						that.itemJson=data;
						if (data.auditFile1) {
							that.auditFile1Path = filePath + "?fileId=" + data.auditFile1Path + "&communityId=" + that.communityId + "&time=" + new Date().getTime();
							that.ImagePreviewList.push(that.auditFile1Path )
						}
						if (data.auditFile2) {
							that.auditFile2Path = filePath + "?fileId=" + data.auditFile2Path + "&communityId=" +that.communityId + "&time=" + new Date().getTime();
							that.ImagePreviewList.push(that.auditFile2Path )
						}
						if (data.auditFile3) {
							that.auditFile3Path = filePath + "?fileId=" + data.auditFile3Path + "&communityId=" + that.communityId + "&time=" + new Date().getTime();
							that.ImagePreviewList.push(that.auditFile3Path )
						}
						console.log('图片地址',that.auditFile1Path )
					}else{
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		// 提交审核
		examineSubmit(auditStatus){
			let that=this;
			let url=that.host+'/app/userAudit.frontAuditUserAudit';
			// let url=that.host+'/app/userAudit.auditUserAudit';
			if ( !auditStatus && !that.refuseReasonValue) {
				that.showErrorMsg=true;
				that.errormsg='请填写拒绝原因！';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return;
			}
			let params={
				auditStatus: auditStatus,
				auditId: that.auditId,
				approveUserId: that.userId,
				refuseReason:that.refuseReasonValue,
				wxAppId: '',
			}
			if(that.submitBstap==false){
				return;
			}
			that.submitBstap=false
			$.ajax({
				url : url,
				type: 'POST',
				dataType:'json',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					console.log('提交审核',res);
					that.submitBstap=true
					if(res.code=='0'){
						that.showErrorMsg=true;
						that.errormsg='审核成功！';
						setTimeout(function(){
							that.showErrorMsg=false;
						},1500)
						window.location.href='../../examineDetail.html?auditId='+that.auditId	
					}else{
						that.errorPopup=true;
						that.submitBstap=true
						that.msg=res.msg
					}
				},
				error:function(res){
					that.errorPopup=true;
					that.submitBstap=true
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		goback(){
			window.history.go(-1); 
		},
		ImagePreview(){
			var that=this;
			vant.ImagePreview(that.ImagePreviewList)
		}
	}
});